import java.io.*;
import java.util.*;

public class HexChromo extends BinaryChromo
{ 
  char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
						'A', 'B', 'C', 'D', 'E', 'F' };
  
  public HexChromo()
  { 
    //  Set gene values to a random sequence of hex chars
    // 	(The chromosome is in a 2's complement hex representation)
		char randomDigit;
		Random random = new Random();
      StringBuilder sb = new StringBuilder();
		for (int i=0; i<Parameters.numGenes; i++)
		{
			for (int j=0; j<Parameters.geneSize; j++)
			{
				randomDigit = hexDigits[random.nextInt(hexDigits.length)];  
				sb.append(randomDigit);
			}
		}
      this.chromo = sb.toString();

		this.rawFitness = -1;   //  Fitness not yet evaluated
		this.sclFitness = -1;   //  Fitness not yet scaled
		this.proFitness = -1;   //  Fitness not yet proportionalized
  }
  
  //  Mutate a Chromosome Based on Mutation Type *****************************
  
  public void doMutation(){

		String mutChromo = "";
		char x, randomDigit;
		Random random = new Random();

		switch (Parameters.mutationType){

		case 1:     //  Replace with new random hex char

			for (int j=0; j<(Parameters.geneSize * Parameters.numGenes); j++){
				x = this.chromo.charAt(j);
				char temp;
				double randnum = Search.r.nextDouble();
				if (randnum < Parameters.mutationRate){
					// Replace x with a random character
					do{
					randomDigit = hexDigits[random.nextInt(hexDigits.length)];  
					}while(x != randomDigit);	
					x = randomDigit;				
				}
				mutChromo = mutChromo + x;
			}
			this.chromo = mutChromo;
			break;

		default:
			System.out.println("ERROR - No mutation method selected");
		}
	}
}
